<?php
include("include/conn.php");
require('include/Smarty/libs/Smarty.class.php');
$garnuMasterId          = "";
$garnuMasterIdArray     = array();
$weightList             = "";
$touchList              = "";
$silverList             = "";
$copperList             = "";
$garnuTotalWeight       = "";
$garnuReturnTotalWeight = "";
$garnuTotalGhat         = "";
$garnuTotalTouch        = "";
$garnuTotalSilver       = "";
$garnuTotalCopper       = "";
$fromDate               = 0;
$toDate                 = 0;
$partyIdFilterSelected  = 0;

if(isset($_REQUEST['fromDateYear']))
	$fromDate  = $_REQUEST['fromDateYear']."-".$_REQUEST['fromDateMonth']."-".$_REQUEST['fromDateDay'];
else
	$fromDate  = date("Y-m-d");

if(isset($_REQUEST['toDateYear']))
	$toDate    = $_REQUEST['toDateYear']."-".$_REQUEST['toDateMonth']."-".$_REQUEST['toDateDay'];
else
	$toDate    = date("Y-m-d");
  
//// Listing of Garnu Data : Starts
$selectGarnuQuery = "SELECT garnuMasterId,garnuName,DATE_FORMAT(garnuDate,'%d-%m-20%y') AS garnuDate,weight,returnWeight,touch,silver,copper
                       FROM garnumaster
                      WHERE 1 = 1 ";
$selectGarnuQuery .= " AND garnumaster.garnuDate <= '".$toDate."'";
$selectGarnuQuery .= " ORDER BY garnuMasterId DESC,garnuDate DESC";
$selectGarnuQueryResult = mysql_query($selectGarnuQuery);
$l = 0;
while($garnuRow = mysql_fetch_array($selectGarnuQueryResult))
{
  $garnuMasterIdArray[$l]['garnuMasterId'] = $garnuRow['garnuMasterId'];
  $garnuMasterIdArray[$l]['garnuName']     = $garnuRow['garnuName'];
  $garnuMasterIdArray[$l]['garnuDate']     = $garnuRow['garnuDate'];
  $garnuMasterIdArray[$l]['weight']        = $garnuRow['weight'];
  $garnuMasterIdArray[$l]['returnWeight']  = $garnuRow['returnWeight'];
  $garnuMasterIdArray[$l]['ghat']          = $garnuRow['weight'] - $garnuRow['returnWeight'];
  $garnuMasterIdArray[$l]['touch']         = $garnuRow['touch'];
  $garnuMasterIdArray[$l]['silver']        = $garnuRow['silver'];
  $garnuMasterIdArray[$l]['copper']        = $garnuRow['copper'];
  $garnuTotalWeight       += $garnuRow['weight'];
  $garnuReturnTotalWeight += $garnuRow['returnWeight'];
  $garnuTotalGhat         += $garnuRow['weight'] - $garnuRow['returnWeight'];
  $garnuTotalTouch        += $garnuRow['touch'];
  $garnuTotalSilver       += $garnuRow['silver'];
  $garnuTotalCopper       += $garnuRow['copper'];
  $l++;
}

//// Listing of Garnu Data : Ends

$smarty = new Smarty;
require('bottom.php');
$smarty->assign("l",$l);
$smarty->assign("garnuMasterId",$garnuMasterId);
$smarty->assign("garnuMasterIdArray",$garnuMasterIdArray);
$smarty->assign("weightList",$weightList);
$smarty->assign("touchList",$touchList);
$smarty->assign("silverList",$silverList);
$smarty->assign("copperList",$copperList);
$smarty->assign("garnuTotalWeight",$garnuTotalWeight);
$smarty->assign("garnuReturnTotalWeight",$garnuReturnTotalWeight);
$smarty->assign("garnuTotalGhat",$garnuTotalGhat);
$smarty->assign("garnuTotalTouch",$garnuTotalTouch);
$smarty->assign("garnuTotalSilver",$garnuTotalSilver);
$smarty->assign("garnuTotalCopper",$garnuTotalCopper);
$smarty->assign("fromDate",$fromDate);
$smarty->assign("toDate",$toDate);
$smarty->assign("partyIdFilterSelected",$partyIdFilterSelected);
$smarty->display('garnuList.tpl');
?>